package orz.itrip.biz.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import orz.itrip.DtoUtils;
import orz.itrip.biz.service.HotelService;
import orz.itrip.dto.Dto;
import orz.itrip.mapper.HotelMapper;
import orz.itrip.mapper.LabelDicMapper;
import orz.itrip.pojo.AreaDic;
import orz.itrip.pojo.Hotel;
import orz.itrip.pojo.Image;
import orz.itrip.pojo.LabelDic;
import orz.itrip.vo.HotelDetailsVo;
import orz.itrip.vo.HotelVedioReVo;
import orz.itrip.vo.HotelVedioVo;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service
public class HotelServiceImpl implements HotelService {

    @Resource
    private HotelMapper hotelMapper;
    @Resource
    private LabelDicMapper labelDicMapper;
    @Override
    public Dto getvideodesc(Long hotelId) {
        HotelVedioVo hotelVedioVo = hotelMapper.selectVedio(hotelId);
        HotelVedioReVo hotelVedioReVo = new HotelVedioReVo();
        if (hotelVedioVo!=null){
            hotelVedioReVo.setHotelName(hotelVedioVo.getHotelName());
            hotelVedioReVo.setHotelFeatureList(hotelVedioVo.getHotelFeatureList().split(","));
            hotelVedioReVo.setTradingAreaNameList(hotelVedioVo.getTradingAreaNameList().split(","));
            return DtoUtils.getSuccesWithData(hotelVedioReVo,"获取酒店视频文字描述成功");
        }
        return DtoUtils.getFalseDto("获取酒店视频文字描述失败","50001");
    }

    @Override
    public Dto queryhoteldetails(Long hotelId) {
        List<HotelDetailsVo> hotelDetailsVos = hotelMapper.selectByDetails(hotelId);
        if (hotelDetailsVos!=null){
            return DtoUtils.getSuccesWithData(hotelDetailsVos,null);
        }
        return DtoUtils.getFalseDto("获取信息失败","50002");
    }

    @Override
    public Dto queryhotelfacilities(Long hotelId) {
        Hotel hotel = hotelMapper.selectByPrimaryKey(hotelId);
        if (hotel!=null){
            return DtoUtils.getSuccesWithData(hotel.getFacilities(),null);
        }
        return DtoUtils.getFalseDto("获取信息失败","50002");
    }

    @Override
    public Dto queryhotelpolicy(Long hotelId) {
        Hotel hotel = hotelMapper.selectByPrimaryKey(hotelId);
        if (hotel!=null){
            return DtoUtils.getSuccesWithData(hotel.getHotelPolicy(),null);
        }
        return DtoUtils.getFalseDto("获取信息失败","50002");
    }
    @Override
    public Dto getimg(Long hotelId) {
        List<Image> images = hotelMapper.selectImage(hotelId,0);
        if (images!=null){
            return DtoUtils.getSuccesWithData(images,"获取酒店图片房型成功");
        }
        return DtoUtils.getFalseDto("获取酒店图片房型失败","50003");
    }

    @Override
    public Dto queryhotcity(Long isChina) {
        List<AreaDic> areas = hotelMapper.selectHotCity(isChina);
        System.out.println(areas);
        if (areas!=null){
            return DtoUtils.getSuccesWithData(areas,null);
        }
        return DtoUtils.getFalseDto(null,"50003");
    }

    @Override
    public Dto queryhotelfeature() {
        LabelDic labelDic = new LabelDic();
        labelDic.setParentId(16L);
        List<LabelDic> labelDics = labelDicMapper.select(labelDic);
        if (labelDics!=null){
            return DtoUtils.getSuccesWithData(labelDics,null);
        }
        return DtoUtils.getFalseDto(null,"50004");
    }

    @Override
    public Dto querytradearea(Long cityId) {
        List<AreaDic> areaDics = hotelMapper.selectCityArea(cityId);
        if (areaDics!=null){
            return DtoUtils.getSuccesWithData(areaDics,null);
        }
        return DtoUtils.getFalseDto(null,"50005");
    }
}
